package com.item.yxlottery.yxlottery.activity;

/*
 *------------------------------
 * @创建者      Administrator
 * @创建时间    2016/11/16 10:14
 * @文件描述    首界面
 *------------------------------
 */

import android.content.Intent;
import android.os.CountDownTimer;
import android.os.Handler;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.flyco.animation.BounceEnter.BounceEnter;
import com.flyco.animation.ZoomExit.ZoomOutExit;
import com.flyco.dialog.listener.OnBtnClickL;
import com.flyco.dialog.widget.NormalDialog;
import com.item.yxlottery.yxlottery.R;
import com.item.yxlottery.yxlottery.base.BaseActivity;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.Bind;
import butterknife.ButterKnife;

public class SplashActivity extends BaseActivity {

    @Bind(R.id.iv_splash_image)
    ImageView mIvImage;
    private int mSecond;
    private MyCounttDownTimer mCounttDownTimer;

    @Override
    protected void setCustomActionBar(ImageButton ibActionbarLeft, TextView tvActionBarTitle, ImageButton ibActionbarRight, AutoRelativeLayout layoutActionbar) {
        layoutActionbar.setVisibility(View.GONE);
    }

    @Override
    protected View initView() {
        View view = View.inflate(this, R.layout.activity_splash, null);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    protected void initData() {
        Glide.with(this).load(R.drawable.icon_splash_bg).into(mIvImage);

        //        mCounttDownTimer = new MyCounttDownTimer(6000, 1000);
        //        mCounttDownTimer.start();

        //延时5秒进去主界面
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                startActivity(new Intent(SplashActivity.this, HomeActivity.class));
                SplashActivity.this.finish();
            }
        }, 5000);
    }

    @Override
    protected void initEvent() {

        //获取最新版本信息
        //        OkHttpUtils.post().url(UrlUtil.getLotteryAdvListURL()).addParams("pageNo", "0").addParams("pageSize", "10").build()
        //                .execute(new MyStringCallBack() {
        //                    @Override
        //                    public void onError(Call call, Exception e, int id) {
        //
        //                    }
        //
        //                    @Override
        //                    public void onResponse(String response, int id) {
        //                        JSONObject parse = (JSONObject) JSON.parse(response);
        //                        if (parse.getString("error_code").equals(Constant.SUCCESS)) {
        //                            //解析数据
        //                            newVersionWarningDialog();
        //                        }
        //                    }
        //                });
    }

    /*- 新版本提示对话框 -*/
    private void newVersionWarningDialog() {
        final NormalDialog dialog = new NormalDialog(this);
        dialog.title("新版本提醒").isTitleShow(true).content("有最新版本,是否更新?").style(NormalDialog.STYLE_TWO).cornerRadius(20)
                .titleTextSize(23).btnText("确定", "取消").btnTextSize(16, 16).btnPressColor(0xff5555)
                .showAnim(new BounceEnter()).dismissAnim(new ZoomOutExit()).show();
        dialog.setOnBtnClickL(
                new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {
                        dialog.dismiss();
                    }
                },
                new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {
                        dialog.dismiss();
                    }
                });
    }

    /*- 自定义倒计时内部类 -*/
    public class MyCounttDownTimer extends CountDownTimer {

        public MyCounttDownTimer(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onFinish() {
            startActivity(new Intent(SplashActivity.this, HomeActivity.class));
            SplashActivity.this.finish();
        }

        @Override
        public void onTick(long millisUntilFinished) {
            mSecond = (int) (6 - millisUntilFinished / 1000);//倒计时6秒的时间
        }
    }
}
